import {
  Inject,
  Controller,
  Get,
  Post,
  Query,
  Body,
} from '@midwayjs/decorator';

import { Context } from '@midwayjs/koa';
import { MessageService } from '../service/message.service';

@Controller('api')
export class MessageController {
  @Inject()
  ctx: Context;

  @Inject()
  messageService: MessageService;

  /**
   * 获取一对一聊天消息
   */
  @Get('/getOneChatMessage')
  async getOneChatMessage(
    @Query('fromId') fromId: number,
    @Query('toId') toId: number
  ): Promise<any> {
    const result = await this.messageService.getOneChatMessage(fromId, toId);
    return result;
  }
  /**
   * 获取首页消息列表
   */
  @Get('/getHomeMsgList')
  async getHomeMsgList(): Promise<any> {
    const result = await this.messageService.getHomeMsgList();
    return result;
  }
  /**
   * 重置未读数
   */
  @Post('/resetUnread')
  async resetUnread(
    @Body('chatType') chatType: number,
    @Body('fromId') fromId: number,
    @Body('toId') toId: number
  ): Promise<any> {
    const result = await this.messageService.resetUnread(
      chatType,
      fromId,
      toId
    );
    return result;
  }
}
